package net.pimpas.web.jsf.renderers;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;

import net.pimpas.web.jsf.components.UIComponentPimpasBase;
import net.pimpas.web.jsf.resourcemanager.ResourceManager;

public class RendererBase extends Renderer {

	private ResourceManager resourceManager;
	private static final String PIMPAS_JS_FRAMEWORK_BASE = "js/pimpas/";
	private static final String[] PIMPAS_JS_FRAMEWORK = {
		"pimpas-full-release.js"
		/*
		"pimpas.js",
		"detect.js",
		"log.js",
		"timer.js",
		"interval.js",
		"listener.js",
		"dom.js",
		"event.js",
		"httpRequest.js",
		"xml.js",
		"xpath.js",
		"ajax.js",
		"ajaxPopulate.js",
		"populate/input.js",
		"populate/select.js",
		"populate/radio.js",
		"populate/checkbox.js",
		"populate/html.js"
		*/
	};
	
	protected void initResourceManager( FacesContext context, UIComponent component ) {
		this.setResourceManager(new ResourceManager(context, component.getClass()));
		// give support to pimpas javascript framework
		for(int i=0;i<PIMPAS_JS_FRAMEWORK.length;i++)
			this.getResourceManager().addCustomJavascriptHeader(PIMPAS_JS_FRAMEWORK_BASE+PIMPAS_JS_FRAMEWORK[i],
					UIComponentPimpasBase.class);
	}

	public ResourceManager getResourceManager() {
		return resourceManager;
	}

	public void setResourceManager(ResourceManager resourceManager) {
		this.resourceManager = resourceManager;
	}
}